package com.c7.servlet;

import com.c7.bean.NewsBean;
import com.c7.dan.NewsDao;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

@WebServlet("/news.jsp")
public class NewsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // todo 获取分页页码参数
        //1.获取新闻信息
        NewsDao newsDao = new NewsDao();
        List<NewsBean> news = newsDao.getList();
        //2.传递新闻信息给前端页面
        req.setAttribute("news", news);
        //3.加载显示前端页面
        req.getRequestDispatcher("newstemp.jsp").forward(req, resp);
    }
}
